{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bf6f3210",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# EduGuide – Study Abroad Consultancy Chatbot\n",
    "\n",
    "EduGuide is an AI-powered education consultancy assistant designed to guide students through the entire process of studying abroad. It provides country/program recommendations, eligibility insights, cost estimates, scholarship advice, visa basics, and step-by-step application planning.\n",
    "\n",
    "## Features\n",
    "\n",
    "### 1. Personalized Study-Abroad Guidance\n",
    "\n",
    "EduGuide collects essential profile details such as:\n",
    "\n",
    "* Current country & citizenship\n",
    "* Academic background (qualification, GPA)\n",
    "* Intended level (Bachelor’s/Master’s/PhD)\n",
    "* Field of study\n",
    "* Budget\n",
    "* Test scores (IELTS/TOEFL/PTE, GRE/GMAT)\n",
    "* Preferred destinations\n",
    "* Target intake (Fall/Spring etc.)\n",
    "\n",
    "### 2. Country & Program Recommendations\n",
    "\n",
    "* Suggests 3–5 suitable countries based on profile and goals\n",
    "* Provides 5–10 matching programs\n",
    "* Includes eligibility ranges (GPA, test scores, experience)\n",
    "\n",
    "### 3. Cost & Scholarship Insights\n",
    "\n",
    "* Estimated tuition + living expenses\n",
    "* Funding options and likely scholarship eligibility\n",
    "* Advice for budget-constrained applicants\n",
    "\n",
    "### 4. Visa & Documentation Support\n",
    "\n",
    "* Overview of visa types\n",
    "* Common document checklists\n",
    "* Practical guidance for smooth preparation\n",
    "\n",
    "### 5. Step-by-Step Timeline\n",
    "\n",
    "* Custom 6–12 week application timeline\n",
    "* Tasks prioritized from profile completion to visa filing\n",
    "\n",
    "### 6. Ready-to-Use Templates\n",
    "\n",
    "* Email to admissions office\n",
    "* SOP/Personal Statement prompts\n",
    "* Academic CV outline\n",
    "* Interview practice questions\n",
    "\n",
    "### 7. Safety & Accuracy\n",
    "\n",
    "EduGuide does **not** guarantee visas, admissions, or legal outcomes.\n",
    "It encourages students to verify policies with official university and embassy sources.\n",
    "\n",
    "---\n",
    "\n",
    "## How It Works\n",
    "\n",
    "1. The system prompt initializes EduGuide with expertise in international education consultancy.\n",
    "2. The chatbot gathers missing details to personalize its advice.\n",
    "3. Students ask questions such as:\n",
    "\n",
    "   * *Which country is best for Computer Science?*\n",
    "   * *Am I eligible for a UK Master’s program?*\n",
    "   * *What is the cost of studying in Canada?*\n",
    "   * *How do I write an SOP?*\n",
    "4. EduGuide responds with structured, concise, and practical guidance.\n",
    "\n",
    "---\n",
    "\n",
    "## Setup Instructions\n",
    "\n",
    "1. Add the system prompt to your chatbot (OpenAI, n8n, FastAPI, WhatsApp bot, or any other platform).\n",
    "2. Route all student queries to this model with the system prompt active.\n",
    "3. (Optional) Store user profile data in your backend or CRM to provide continuity across chats.\n",
    "\n",
    "---\n",
    "\n",
    "## Example Query\n",
    "\n",
    "**Student:**\n",
    "“I have a Bachelor’s in IT with 2.8 CGPA, IELTS 6.5, and want to study in Europe. My budget is low. Options?”\n",
    "\n",
    "**EduGuide Response Includes:**\n",
    "\n",
    "* Matchable countries (Germany, Poland, Finland, Hungary)\n",
    "* Program shortlist\n",
    "* Cost estimates\n",
    "* Scholarships and tuition-free routes\n",
    "* Visa basics\n",
    "* A 6–12 week action plan\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9cd276b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from openai import OpenAI\n",
    "import gradio as gr\n",
    "from dotenv import load_dotenv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "81869861",
   "metadata": {},
   "outputs": [],
   "source": [
    "load_dotenv(override=True)\n",
    "open_api_key = os.environ.get(\"OPENAI_API_KEY\")\n",
    "MODEL=\"gpt-4.1-mini\"\n",
    "openai = OpenAI()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b219ae84",
   "metadata": {},
   "outputs": [],
   "source": [
    "system_message = \"\"\"You are EduGuide — an expert education-consultant chatbot for students planning to study abroad. Provide accurate, actionable guidance on country & program choice, entry requirements, application timelines, document checklists, tests (IELTS/TOEFL/PTE, GRE/GMAT), scholarships & funding, cost estimates (tuition + living), visa basics, and post-acceptance steps (housing, insurance, arrival).\n",
    "\n",
    "When advising, first collect minimal profile data needed: current country & citizenship, highest qualification + GPA, intended level (Bachelors/Masters/PhD/diploma), field of study, preferred destination(s), budget, English/test scores (if any), desired start term, timeline, and constraints (work experience, dependents, scholarship need). Request only missing items required to personalize advice.\n",
    "\n",
    "For each request produce:\n",
    "- 3–5 recommended destination countries and why.\n",
    "- 5–10 matching programs (one safety, one stretch) with typical eligibility and cutoff indicators.\n",
    "- Estimated annual cost range (tuition + living) with currency and year.\n",
    "- Relevant scholarship types and likely eligibility.\n",
    "- Visa overview and common required documents.\n",
    "- Prioritized next-step checklist and a tailored 6–12 week application timeline with deadlines.\n",
    "- Ready-to-use templates: inquiry email to admissions, CV outline, SOP prompts, and 5 mock interview questions.\n",
    "\n",
    "When giving factual policy, cite sources or advise the user to verify on official university/embassy pages. If asked for legal/financial/visa guarantees or diagnoses, refuse and refer to qualified authorities. Keep responses concise, professional, and actionable. Ask follow-up questions only when necessary to deliver a correct, personalized plan.\"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "716db05f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def chat(message, history):\n",
    "    history = [{\"role\":h[\"role\"], \"content\":h[\"content\"]} for h in history]\n",
    "    messages = [{\"role\": \"system\", \"content\": system_message}] + history + [{\"role\": \"user\", \"content\": message}]\n",
    "    stream = openai.chat.completions.create(model=MODEL, messages=messages, stream=True)\n",
    "    response = \"\"\n",
    "    for chunk in stream:\n",
    "        response += chunk.choices[0].delta.content or ''\n",
    "        yield response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "047670e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "chatView = gr.ChatInterface(\n",
    "    fn=chat, \n",
    "    type='messages',\n",
    "    title=\"Welcome to EduGuide Consultancy 📖\",\n",
    "    description=\"EduGuide is an AI-powered education consultancy assistant designed to guide students through the entire process of studying abroad. It provides country/program recommendations, eligibility insights, cost estimates, scholarship advice, visa basics, and step-by-step application planning.\",\n",
    "    examples=[\"How to study in Canada?\", \"What are the best IT Universities in Austrailia\",\n",
    "    \"Best universities for Medical Sciences.\"],\n",
    "    )\n",
    "\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eab3e607",
   "metadata": {},
   "outputs": [],
   "source": [
    "chatView.launch(inbrowser=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43a3b996",
   "metadata": {},
   "outputs": [],
   "source": [
    "chatView.close()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da1cdce6",
   "metadata": {},
   "source": [
    "### Conclusion:\n",
    "\n",
    "This chatbot will really be helpful once we can embed some knowledge base in it."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
